type Toptions_Pcheckbox = Omit<Toptions_CDVP, 'multiple'> & {
    /** true: 多选（显示为checkbox）; null: 单选（显示为checkbox）; false: 单选（显示为radio）; */
    multiple?: boolean | null;
};

@ACdisabled
@ACreadonly
@AConchange
@ACcontrols
@ACname
@ACdata
class Pcheckbox extends _CDVP_<Toptions_Pcheckbox> {
    // ====================================================== 当前控件特殊实现 ====================================================== //
    // @ts-ignore Property '_item_type_' has no initializer and is not definitely assigned in the constructor.ts(2564)
    private _item_type_: string;
    // @ts-ignore Property '_item_class_' has no initializer and is not definitely assigned in the constructor.ts(2564)
    private _item_class_: string;
    // @ts-ignore Property 'name' has no initializer and is not definitely assigned in the constructor.ts(2564)
    private name: string;
    // @ts-ignore Property 'container' has no initializer and is not definitely assigned in the constructor.ts(2564)
    private container: KHTMLElement;

    // ====================================================== 初始化参数 ====================================================== //
    static defaultOptions: Toptions_Pcheckbox = {
        multiple: true,
    };
    protected override options_default(): Toptions_Pcheckbox {
        return Pcheckbox.defaultOptions;
    }
    protected override options_handlers(): Toptions_handlers<Toptions_Pcheckbox> {
        return {
            multiple: {
                [Etype.boolean]: U.F.fn.obj,
                [Etype.null]: U.F.fn.obj,
            }
        };
    }
    protected override overloading_mapping(mapping: Toption_key_to_types_mapping<Toptions_Pcheckbox>): Toverloading_mapping<Toptions_Pcheckbox> {
        return [
        ];
    }
    protected override options_checker(options: Toptions_Pcheckbox): void {
        if (Object.prototype.hasOwnProperty.call(options, 'multiple')) {
            if (options.multiple === null) {
                this._item_type_ = 'radio';
                this._item_class_ = 'checkradio';
            } else {
                if (options.multiple) {
                    this._item_type_ = 'checkbox';
                    this._item_class_ = 'checkbox';
                } else {
                    this._item_type_ = 'radio';
                    this._item_class_ = 'radio';
                }
            }
        } else {
            this._item_type_ = 'checkbox';
            this._item_class_ = 'checkbox';
        }
    }

    // ====================================================== 创建实例对象 ====================================================== //
    protected override initializer(): void {
        this.container = this.ele.createElement('div').addClass('container');
        this.name = U.S.randomString(6);
    }
    protected override afterInitializer(): void {
    }

    // ====================================================== 创建数据值控件实例对象 ====================================================== //
    protected override item_render(dataI: Toptions_DATA$dataI, text: string, value: any) {
        const ele_wrap = this.container!.createElement('div').addClass('wrap');

        const optionId = U.S.randomString(6);

        // 输入项
        const ele_item = ele_wrap.createElement('input')
            .addClass(_CP_.CLASSES.INPUTER)
            .addClass(_CP_.CLASSES.INPUTER + '_' + this._item_class_)
            .setAttr('type', this._item_type_)
            .setAttr('id', optionId)
            .setAttr('name', this.name);

        // 伪类
        ele_wrap.createElement('label').setAttr('for', optionId);

        // 文本
        ele_wrap.createElement('label').setAttr('for', optionId).setAttr('textContent', text);

        return ele_item.ele()!;
    }
    public override getValue(): any {
        const result: any = [];
        this.items.forEach(ele_item => {
            if ((ele_item as HTMLInputElement).checked === true) {
                result.push((ele_item as any).dataValue);
            }
        });
        return result;
    }
    public override setValue(value: any): void {
        if (Array.isArray(value)) {
            this.items.forEach(ele_item => {
                (ele_item as HTMLInputElement).checked = false;// 先清空选中状态
                if (value.indexOf((ele_item as any).dataValue) >= 0) {
                    (ele_item as HTMLInputElement).checked = true;
                }
            });
        } else if (value === DEFAULT) {
            this.items.forEach(ele_item => {
                (ele_item as HTMLInputElement).checked = false;// 先清空选中状态
            });
        } else {
            this.items.forEach(ele_item => {
                (ele_item as HTMLInputElement).checked = false;// 先清空选中状态
                if (value === (ele_item as any).dataValue) {
                    (ele_item as HTMLInputElement).checked = true;
                }
            });
        }
    }
}

interface _IK_ {
    // ========= 创建实例对象（通用） ========= //
    /**
     * 创建控件
     * @returns 控件实例对象
     */
    checkbox(): KHTMLElement;

    /**
     * 创建控件
     * @param options 控件参数
     * @returns 控件实例对象
     */
    checkbox(options: Toptions_Pcheckbox): KHTMLElement;

    // ========= 创建实例对象（数据值控件） ========= //
    /**
     * 创建控件
     * @param data 数据
     * @returns 控件实例对象
     */
    checkbox(data: Array<Toptions_DATA$dataI>): KHTMLElement;
}
{
    K.checkbox = (...args: Array<any>) => { return new Pcheckbox(...args).ele; };
}
